package com.group1.realtime.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author lzc
 * @Date 2022/7/18 14:20
 */
public class AtguiguUtil {
    public static String toDate(Long ts) {
        return new SimpleDateFormat("yyyy-MM-dd").format(ts);
    }
    
    public static String toYesterday(Long ts) {
        return toDate(ts - 24 * 60 * 60 * 1000);
    }
    
    public static <T>List<T> toList(Iterable<T> it) {
        List<T> list = new ArrayList<>();
        it.forEach(list::add);
        return list;
    }
    
    public static String toDateTime(long ts) {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(ts);
    }
    
    public static long dateToTs(String date) throws ParseException {
        return new SimpleDateFormat("yyyy-MM-dd").parse(date).getTime();
    }
    
    /*
    比较 one是否大于 tow
    是 true
    否 false
     */
    public static boolean compareLTZ(String one, String two) {
        one = one.replaceAll("Z","");
        two = two.replaceAll("Z","");
        
        return one.compareTo(two) > 0;
    }
}
